/*!
* @file Color.h
* @brief 颜色
* @date 2024/9/13
*/
#pragma once

#include <cmath>
#include <ostream>
#ifdef __GNUC__
# include <cstdint>
#endif
#include "DataDef.h"

namespace data
{
/*!
* @brief 颜色
*/
class DATA_API Color
{
public:
    /*!
    * @brief 开放成员
    */
    float r, g, b, a;

    /*!
    * @brief 颜色构造
    */
    explicit Color(float red = 0.0, float green = 0.0, float blue = 0.0, float alpha = 1.0);
    explicit Color(int rgba);
    Color(const Color& c) = default;
    Color(Color&&) = default;

    /*!
    * @brief 颜色运算
    */
    Color& operator=(const Color& c) = default;
    Color& operator=(Color && c) = default;
    bool operator==(const Color& c) const;
    bool operator!=(const Color& c) const;

    /*!
    * @brief 颜色操作
    */
    void Set(float R,float G, float B, float A=0.0);
    int GetRGBA() const;
    void SetRGBA(int rgba);
    int GetRGB() const;
    void SetRGB(int);
    int GetARGB() const;
    void SetARGB(int);

    /*!
    * @brief 数据转换
    */
    template <typename T>
    inline void SetValue(const T& q) { set(q.redF(),q.greenF(),q.blueF());}
    template <typename T>
    inline T GetValue() const
    {
        // clang-format off
        return(T(int(std::lround(r * 255.0F)),
                 int(std::lround(g * 255.0F)),
                 int(std::lround(b * 255.0F))));
        // clang-format on
    }

    /*!
    * @brief 文本信息输出
    */
    friend std::ostream& operator<< (std::ostream& stream, const Color& c)
    {
        return stream << "{ r: " << c.r << ", g: " << c.g << ", b: " << c.b << " a: " << c.a << " }";
    }
};

} //namespace data
